package com.zhu.mapper.annotation.autoMapping;

import com.zhu.mapper.typeHandler.SessionTypeHandler;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.apache.shiro.session.Session;

import java.util.List;
import java.util.Map;

/**
 * Created by DELL on 2015/12/31.
 */
public interface SessionDAO {

    @Insert("insert into z_session(key, session) values(#{session.id},#{session, javaType=org.apache.shiro.session.Session})")
    int saveSession(@Param("session") Session session);

    @Insert("insert into z_session(key, session) values(#{key},#{session, javaType=org.apache.shiro.session.Session})")
    int saveSession2(Map<String, Object> map);

    @Update("update  z_session set session=#{session} where key=#{session.id}")
    int updateSession(Session session);

    @Delete("delete from z_session where key=#{key}")
    int deleteSession(String key);

    @Select("select session from z_session where key=#{key}")
    @Results(
            @Result(column = "session", typeHandler = SessionTypeHandler.class)
    )
    Session getSession(String key);

    @Select("select session from z_session where key=#{key}")
    @Results(value={
            @Result(column = "session", typeHandler = SessionTypeHandler.class)
    })
    List<Session> getAllSession();
}
